//
//  DBTable.h
//  iDent
//
//  Created by Marius Corega on 8/5/09.
//  Copyright 2009 Marius Corega. All rights reserved.
//

#import <Cocoa/Cocoa.h>



@interface DBTable : NSObject {

	
	NSMutableArray * _elemente;
	NSMutableDictionary * _element;
	NSMutableString *xmlString;
	//NSXMLParser *parser;
	NSMutableDictionary* _selectedElement;
	
	NSMutableArray* lockedElements;
	
	NSString* _tableName;
	NSString* _elementName;
	NSURL* _url;
	NSURL* _serverURL;
	NSMutableDictionary* _postDict;
	
	
	BOOL isLoadingVersion;
	NSDate* loadTime;
	
	NSString *notification;
	
	NSOperationQueue *q;
}

@property (readwrite) BOOL isLoadingVersion;
@property (readwrite, retain) NSMutableArray * _elemente;


- (id)initWithXMLData: (NSData*) data tableName:(NSString*) tableName elementName:(NSString*) elementName;
-(id)initWithURL:(NSURL*) url tableName:(NSString*) tableName;
-(id)initWithServerURL:(NSURL*) url tableName:(NSString*) tableName;
-(id) initWithServerURL:(NSURL*) url postDict:(NSDictionary*)dict;
-(id)initWithServerURL:(NSURL*) url;

-(NSString*) addElement;
-(NSString*) addElement:(NSDictionary*) dict;
-(BOOL) removeElementWithID:(NSString*) elementID;

-(BOOL) setElementWithID:(NSString*) elementID value:(NSString*)value forField:(NSString*) field;
-(NSString*) getElementWithID:(NSString*) elementID forField:(NSString*) field;
-(BOOL) setElement:(NSDictionary*) postDict;
-(NSDictionary*) getElementWithID:(NSString*) elementID;
-(BOOL) setElementWithID:(NSString*) elementID ;
-(BOOL) reloadElementWithID:(NSString*) elementID;
-(NSMutableDictionary*) elementWithID:(NSString*) elementID;

-(BOOL) lockElementWithID:(NSString*) elementID;
-(BOOL) unlockElementWithID:(NSString*) elementID;
-(BOOL) isLocked:(NSString*) elementID;
-(BOOL) iLockedElementWithID:(NSString*) elementID;
-(void) unlockElements;

-(BOOL) setSelectedElement:(NSMutableDictionary*) dict;
-(NSMutableDictionary*) selectedElement;

- (NSString *)uuid;

-(BOOL)load;
-(BOOL)loadForPacientWithID:(NSString*) pacientID;
-(void)loadForPacientWithIDAsync:(NSString*) pacientID;
-(BOOL)reloadData;
-(void)loadSync;
-(void)loadAsync;

- (NSArray*)elemente;

-(NSDictionary*)postDict;
-(void) setPostDict:(NSDictionary*) dict;

//- (NSArray*)manopereStrings;
-(void)unlockTimerFireMethod:(NSTimer*)theTimer;

@end
